﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TorneoLoL
{
    public partial class FormAlta : Form
    {
        Conexion conexion = new Conexion();
        DataSet dataS;
        Fecha fecha = new Fecha();

        public FormAlta()
        {
            InitializeComponent();
        }        

        private void FormAlta_Load( object sender, EventArgs e )
        {
            cmbEleccion.Items.AddRange( new string[]{"Coaches", "Teams", "Jugadores", "Partidas",
                                        "TeamxPartidas", "Encuentros", "JugadoresXEncuentros", "Usuarios"} );
            resetAllCtrls();
        }

        public void resetAllCtrls()
        {
            lblEleccion.Enabled = false;
            lblEleccion.Visible = false;
            label2.Enabled = false;
            label2.Visible = false;
            label3.Enabled = false;
            label3.Visible = false;
            label4.Enabled = false;
            label4.Visible = false;
            label5.Enabled = false;
            label5.Visible = false;
            label6.Enabled = false;
            label6.Visible = false;
            label7.Enabled = false;
            label7.Visible = false;
            label8.Enabled = false;
            label8.Visible = false;
            label9.Enabled = false;
            label9.Visible = false;
            textBox1.Enabled = false;
            textBox1.Visible = false;
            textBox1.Text = String.Empty;
            textBox1.BackColor = System.Drawing.SystemColors.Window;
            textBox2.Enabled = false;
            textBox2.Visible = false;
            textBox2.Text = String.Empty;
            textBox2.BackColor = System.Drawing.SystemColors.Window;
            textBox3.Enabled = false;
            textBox3.Visible = false;
            this.textBox3.KeyPress -= new System.Windows.Forms.KeyPressEventHandler( this.textBox3_KeyPress );
            textBox3.Text = String.Empty;
            textBox3.BackColor = System.Drawing.SystemColors.Window;
            textBox4.Enabled = false;
            textBox4.Visible = false;
            this.textBox4.KeyPress -= new System.Windows.Forms.KeyPressEventHandler( this.textBox4_KeyPress );
            textBox4.Text = String.Empty;
            textBox4.BackColor = System.Drawing.SystemColors.Window;
            textBox5.Enabled = false;
            textBox5.Visible = false;
            this.textBox5.KeyPress -= new System.Windows.Forms.KeyPressEventHandler( this.textBox5_KeyPress );
            textBox5.Text = String.Empty;
            textBox5.BackColor = System.Drawing.SystemColors.Window;
            textBox6.Enabled = false;
            textBox6.Visible = false;
            textBox6.Text = String.Empty;
            textBox6.BackColor = System.Drawing.SystemColors.Window;
            textBox7.Enabled = false;
            textBox7.Visible = false;
            textBox7.Text = String.Empty;
            textBox7.BackColor = System.Drawing.SystemColors.Window;
            textBox8.Enabled = false;
            textBox8.Visible = false;
            textBox8.Text = String.Empty;
            textBox8.BackColor = System.Drawing.SystemColors.Window;
            comboBox1.Enabled = false;
            comboBox1.Visible = false;
            comboBox1.DataSource = null;
            comboBox1.Items.Clear();
            comboBox1.BackColor = System.Drawing.SystemColors.Window;
            comboBox2.Enabled = false;
            comboBox2.Visible = false;
            comboBox2.DataSource = null;
            comboBox2.Items.Clear();
            comboBox2.BackColor = System.Drawing.SystemColors.Window;
            comboBox3.Enabled = false;
            comboBox3.Visible = false;
            comboBox3.DataSource = null;
            comboBox3.Items.Clear();
            comboBox3.BackColor = System.Drawing.SystemColors.Window;
            comboBox4.Enabled = false;
            comboBox4.Visible = false;
            comboBox4.DataSource = null;
            comboBox4.Items.Clear();
            comboBox4.BackColor = System.Drawing.SystemColors.Window;
            dataS = new DataSet();
            if(dataS.Tables != null)
                dataS.Tables.Clear();
            btnAceptar.Enabled = false;
            btnAceptar.Visible = false;
        }

        private void cmbEleccion_SelectedValueChanged( object sender, EventArgs e )
        {
            resetAllCtrls();
            btnAceptar.Enabled = true;
            btnAceptar.Visible = true;
            dataS = new DataSet();

            switch(cmbEleccion.Text)
            {
                case "Coaches":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Coach:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "Nick:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "Nombre:";
                    label4.Enabled = true;
                    label4.Visible = true;
                    label5.Text = "País:";
                    label5.Enabled = true;
                    label5.Visible = true;
                    label6.Text = "Fecha nacimiento" + Environment.NewLine + "(dd/mm/aaaa):";
                    label6.Enabled = true;
                    label6.Visible = true;

                    textBox1.Visible = true;

                    textBox2.Enabled = true;
                    textBox2.Visible = true;
                    textBox2.Text = String.Empty;
                    
                    textBox3.Enabled = true;
                    textBox3.Visible = true;
                    textBox3.Text = String.Empty;

                    comboBox4.Enabled = true;
                    comboBox4.Visible = true;

                    textBox5.Enabled = true;
                    textBox5.Visible = true;
                    textBox5.Text = String.Empty;
                    this.textBox5.KeyPress += new System.Windows.Forms.KeyPressEventHandler( this.textBox5_KeyPress );
                    

                    conexion.consultarDataSet( ref dataS, "Coaches", "select top 1 C_Id from coaches order by C_Id desc" );
                    try
                    {
                        textBox1.Text = dataS.Tables["Coaches"].Rows[0][0].ToString();
                    }
                    catch( System.IndexOutOfRangeException )
                    {
                        textBox1.Text = "0";
                    }
                    textBox1.Text = (Convert.ToInt16( textBox1.Text ) + 1).ToString();

                    conexion.consultarDataSet( ref dataS, "Paises", "select * from Paises" );
                    try
                    {
                        comboBox4.DataSource = dataS.Tables["Paises"];
                        comboBox4.DisplayMember = "P_Nombre";
                        comboBox4.ValueMember = "P_ID";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Paises", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    break;

                case "Teams":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Team:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "ID Coach:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "País:";
                    label4.Enabled = true;
                    label4.Visible = true;
                    label5.Text = "Nombre";
                    label5.Enabled = true;
                    label5.Visible = true;
                    label6.Text = "Nombre" + Environment.NewLine + "completo:";
                    label6.Enabled = true;
                    label6.Visible = true;

                    textBox1.Visible = true;
                    textBox1.Text = String.Empty;

                    comboBox2.Enabled = true;
                    comboBox2.Visible = true;

                    comboBox3.Enabled = true;
                    comboBox3.Visible = true;

                    textBox4.Enabled = true;
                    textBox4.Visible = true;
                    textBox4.Text = String.Empty;

                    textBox5.Enabled = true;
                    textBox5.Visible = true;
                    textBox5.Text = String.Empty;

                    conexion.consultarDataSet( ref dataS, "Teams", "select top 1 T_IdTeam from teams order by T_IdTeam desc" );
                    try
                    {
                        textBox1.Text = dataS.Tables["Teams"].Rows[0][0].ToString();
                    }
                    catch( System.IndexOutOfRangeException )
                    {
                        textBox1.Text = "0";
                    }
                    textBox1.Text = (Convert.ToInt16( textBox1.Text ) + 1).ToString();

                    conexion.consultarDataSet( ref dataS, "Coaches", "select * from coaches" );
                    try
                    {
                        comboBox2.DataSource = dataS.Tables["Coaches"];
                        comboBox2.DisplayMember = "C_Nombre";
                        comboBox2.ValueMember = "C_Id";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Coaches", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    conexion.consultarDataSet( ref dataS, "Paises", "select * from Paises" );
                    try
                    {
                        comboBox3.DataSource = dataS.Tables["Paises"];
                        comboBox3.DisplayMember = "P_Nombre";
                        comboBox3.ValueMember = "P_ID";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Paises", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    break;

                case "Jugadores":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Jugador:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "ID Team:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "Rol:";
                    label4.Enabled = true;
                    label4.Visible = true;
                    label5.Text = "País:";
                    label5.Enabled = true;
                    label5.Visible = true;
                    label6.Text = "Fecha nacimiento" + Environment.NewLine + "(dd/mm/aaaa):";
                    label6.Enabled = true;
                    label6.Visible = true;
                    label7.Text = "Nombre:";
                    label7.Enabled = true;
                    label7.Visible = true;
                    label8.Text = "Nick:";
                    label8.Enabled = true;
                    label8.Visible = true;

                    textBox1.Visible = true;
                    textBox1.Text = String.Empty;

                    comboBox2.Enabled = true;
                    comboBox2.Visible = true;
                    
                    comboBox3.Enabled = true;
                    comboBox3.Visible = true;
                    
                    comboBox4.Enabled = true;
                    comboBox4.Visible = true;

                    textBox5.Enabled = true;
                    textBox5.Visible = true;
                    textBox5.Text = String.Empty;
                    this.textBox5.KeyPress += new System.Windows.Forms.KeyPressEventHandler( this.textBox5_KeyPress );

                    textBox6.Enabled = true;
                    textBox6.Visible = true;
                    textBox6.Text = String.Empty;

                    textBox7.Enabled = true;
                    textBox7.Visible = true;
                    textBox7.Text = String.Empty;

                    conexion.consultarDataSet( ref dataS, "Jugadores", "select top 1 J_Id from jugadores order by J_Id desc" );
                    try
                    {
                        textBox1.Text = dataS.Tables["Jugadores"].Rows[0][0].ToString();
                    }
                    catch( System.IndexOutOfRangeException )
                    {
                        textBox1.Text = "0";
                    }
                    textBox1.Text = (Convert.ToInt16( textBox1.Text ) + 1).ToString();

                    conexion.consultarDataSet( ref dataS, "Teams", "select * from Teams" );
                    try
                    {
                        comboBox2.DataSource = dataS.Tables["Teams"];
                        comboBox2.DisplayMember = "T_NombreTeam";
                        comboBox2.ValueMember = "T_IdTeam";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Teams", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    conexion.consultarDataSet( ref dataS, "Roles", "select * from roles" );
                    try
                    {
                        comboBox3.DataSource = dataS.Tables["Roles"];
                        comboBox3.DisplayMember = "R_Nombre";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Roles", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    conexion.consultarDataSet( ref dataS, "Paises", "select * from Paises" );
                    try
                    {
                        comboBox4.DataSource = dataS.Tables["Paises"];
                        comboBox4.DisplayMember = "P_Nombre";
                        comboBox4.ValueMember = "P_ID";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Paises", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    break;

                case "Partidas":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Partida:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "Fase:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "Fecha" + Environment.NewLine + "(dd/mm/aaaa):";
                    label4.Enabled = true;
                    label4.Visible = true;

                    textBox1.Visible = true;
                    textBox1.Text = String.Empty;

                    comboBox2.Enabled = true;
                    comboBox2.Visible = true;
                    
                    textBox3.Enabled = true;
                    textBox3.Visible = true;
                    textBox3.Text = String.Empty;
                    this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler( this.textBox3_KeyPress);


                    conexion.consultarDataSet( ref dataS, "Partidas", "select top 1 P_idPartida from partidas order by P_idPartida desc" );
                    try
                    {
                        textBox1.Text = dataS.Tables["Partidas"].Rows[0][0].ToString();
                    }
                    catch( System.IndexOutOfRangeException )
                    {
                        textBox1.Text = "0";
                    }
                    textBox1.Text = (Convert.ToInt16( textBox1.Text ) + 1).ToString();

                    conexion.consultarDataSet( ref dataS, "Fases", "select * from fases" );
                    try
                    {
                        comboBox2.DataSource = dataS.Tables["Fases"];
                        comboBox2.DisplayMember = "F_Fase";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Fases", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    break;

                case "TeamxPartidas":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Partida:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "ID Team:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "Puntos:";
                    label4.Enabled = true;
                    label4.Visible = true;

                    comboBox1.Enabled = true;
                    comboBox1.Visible = true;

                    comboBox2.Enabled = true;
                    comboBox2.Visible = true;

                    textBox3.Enabled = true;
                    textBox3.Visible = true;
                    textBox3.Text = String.Empty;

                    conexion.consultarDataSet( ref dataS, "Partidas", "select * from partidas" );
                    try
                    {
                        comboBox1.DataSource = dataS.Tables["Partidas"];
                        comboBox1.DisplayMember = "P_idPartida";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Partidas", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    conexion.consultarDataSet( ref dataS, "Teams", "select * from teams" );
                    try
                    {
                        comboBox2.DataSource = dataS.Tables["Teams"];
                        comboBox2.DisplayMember = "T_NombreTeam";
                        comboBox2.ValueMember = "T_IdTeam";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Teams", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    break;

                case "Encuentros":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Encuentro:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "ID Partida:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "ID Ganador:";
                    label4.Enabled = true;
                    label4.Visible = true;

                    textBox1.Enabled = true;
                    textBox1.Visible = true;
                    textBox1.Text = String.Empty;

                    comboBox2.Enabled = true;
                    comboBox2.Visible = true;

                    comboBox3.Enabled = true;
                    comboBox3.Visible = true;

                    conexion.consultarDataSet( ref dataS, "Partidas", "select * from partidas" );
                    try
                    {
                        comboBox2.DataSource = dataS.Tables["Partidas"];
                        comboBox2.DisplayMember = "P_idPartida";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Partidas", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }

                    conexion.consultarDataSet( ref dataS, "Teams", "select * from teams" );
                    try
                    {
                        comboBox3.DataSource = dataS.Tables["Teams"];
                        comboBox3.DisplayMember = "T_NombreTeam";
                        comboBox3.ValueMember = "T_IdTeam";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Teams", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }
                    
                    break;

                case "JugadoresXEncuentros":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Encuentro:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "ID Jugador:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "ID Partida:";
                    label4.Enabled = true;
                    label4.Visible = true;
                    label5.Text = "Personaje:";
                    label5.Enabled = true;
                    label5.Visible = true;
                    label6.Text = "Creep Score:";
                    label6.Enabled = true;
                    label6.Visible = true;
                    label7.Text = "Kills:";
                    label7.Enabled = true;
                    label7.Visible = true;
                    label8.Text = "Deaths:";
                    label8.Enabled = true;
                    label8.Visible = true;
                    label9.Text = "Assists:";
                    label9.Enabled = true;
                    label9.Visible = true;

                    comboBox1.Enabled = true;
                    comboBox1.Visible = true;
                    this.comboBox1.SelectedValueChanged += new System.EventHandler( this.cargarPartidasXEncuentro ); 

                    comboBox2.Enabled = true;
                    comboBox2.Visible = true;
                    
                    comboBox3.Enabled = true;
                    comboBox3.Visible = true;
                    
                    textBox4.Enabled = true;
                    textBox4.Visible = true;
                    textBox4.Text = String.Empty;

                    textBox5.Enabled = true;
                    textBox5.Visible = true;
                    textBox5.Text = String.Empty;

                    textBox6.Enabled = true;
                    textBox6.Visible = true;
                    textBox6.Text = String.Empty;

                    textBox7.Enabled = true;
                    textBox7.Visible = true;
                    textBox7.Text = String.Empty;

                    textBox8.Enabled = true;
                    textBox8.Visible = true;
                    textBox8.Text = String.Empty;

                    conexion.consultarDataSet( ref dataS, "Encuentros", "select * from Encuentros" );
                    try
                    {
                        comboBox1.DataSource = dataS.Tables["Encuentros"];
                        comboBox1.DisplayMember = "E_IdEncuentro";
                        comboBox1.ValueMember = "E_IdEncuentro";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show("No se pudo llenar la lista de Encuentros");
                    }

                    conexion.consultarDataSet( ref dataS, "Jugadores", "select * from Jugadores" );
                    try
                    {
                        comboBox2.DataSource = dataS.Tables["Jugadores"];
                        comboBox2.DisplayMember = "J_Nick";
                        comboBox2.ValueMember = "J_Id";
                    }
                    catch(System.Exception)
                    {
                        MessageBox.Show( "No se pudo llenar la lista de Jugadores", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    }
                    break;

                case "Usuarios":
                    lblEleccion.Text = cmbEleccion.Text;
                    lblEleccion.Enabled = false;
                    lblEleccion.Visible = true;
                    label2.Text = "ID Usuario:";
                    label2.Enabled = true;
                    label2.Visible = true;
                    label3.Text = "Usuario:";
                    label3.Enabled = true;
                    label3.Visible = true;
                    label4.Text = "Contraseña:";
                    label4.Enabled = true;
                    label4.Visible = true;
                    label5.Text = "Repita contraseña:";
                    label5.Enabled = true;
                    label5.Visible = true;

                    textBox1.Visible = true;
                    textBox1.Text = String.Empty;

                    textBox2.Enabled = true;
                    textBox2.Visible = true;
                    textBox2.Text = String.Empty;
                    
                    textBox3.Enabled = true;
                    textBox3.Visible = true;
                    textBox3.Text = String.Empty;
                    
                    textBox4.Enabled = true;
                    textBox4.Visible = true;
                    textBox4.Text = String.Empty;


                    conexion.consultarDataSet( ref dataS, "Usuarios", "select top 1 U_ID from Usuarios order by U_ID desc" );
                    try
                    {
                        textBox1.Text = dataS.Tables["Usuarios"].Rows[0][0].ToString();
                    }
                    catch( System.IndexOutOfRangeException )
                    {
                        textBox1.Text = "0";
                    }
                    textBox1.Text = (Convert.ToInt16( textBox1.Text ) + 1).ToString();
                    break;
            }
        }

        private void btnAceptar_Click( object sender, EventArgs e )
        {
            String strErrores = String.Empty;
            String[] Parametros = new String[8];
            SqlCommand comando = new SqlCommand();
            dataS = new DataSet();
            switch(cmbEleccion.Text)
            {
                case "Coaches":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox2.Text.Trim() != String.Empty)
                        {
                            if(textBox2.Text.Length > 20)
                            {
                                strErrores += "Nick demasiado largo." + Environment.NewLine;
                                textBox2.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                conexion.consultarDataSet( ref dataS, "Coaches", "select * from coaches where C_Nick = '" + textBox2.Text + "'" );
                                if(dataS.Tables["Coaches"].Rows[0][0] != null)
                                {
                                    strErrores += "Nick existente. Elija otro." + Environment.NewLine;
                                    textBox2.BackColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    if(textBox2.Text.All( char.IsDigit ))
                                    {
                                        strErrores += "No se admiten números en el nick" + Environment.NewLine;
                                        textBox2.BackColor = System.Drawing.Color.Red;
                                    }
                                    else
                                        Parametros[0] = textBox2.Text;
                                }
                            }
                        }
                        else
                        {
                            strErrores += "Nick vacío." + Environment.NewLine;
                            textBox2.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        if(textBox2.Text.All( char.IsDigit ))
                        {
                            strErrores += "No se admiten números en el nick" + Environment.NewLine;
                            textBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                            Parametros[0] = textBox2.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += err.Message + Environment.NewLine;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if( textBox3.Text.Trim() != String.Empty)
                    {
                        if(textBox3.Text.Length > 25)
                        {
                            strErrores += "Nombre demasiado largo." + Environment.NewLine;
                            textBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            if(textBox3.Text.All( char.IsDigit ))
                            {
                                strErrores += "No se admiten números en el nombre" + Environment.NewLine;
                                textBox3.BackColor = System.Drawing.Color.Red;
                            }
                            else
                                Parametros[1] = textBox3.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Nombre vacío." + Environment.NewLine;
                        textBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox4.Items.IndexOf( (comboBox4.SelectedItem) ) < 0)
                        {
                            strErrores += "País no válido." + Environment.NewLine;
                            comboBox4.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            try
                            {
                                if(comboBox4.Text.Trim() != String.Empty)
                                {
                                    Parametros[3] = comboBox4.SelectedValue.ToString();
                                }
                                else
                                {
                                    strErrores += "País vacío." + Environment.NewLine;
                                    comboBox4.BackColor = System.Drawing.Color.Red;
                                }
                            }
                            catch(System.IndexOutOfRangeException)
                            {
                                Parametros[3] = comboBox4.SelectedValue.ToString();
                            }
                            catch(System.Exception err)
                            {
                                strErrores += "Error País. " + err.Message + Environment.NewLine;
                                comboBox4.BackColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb4, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox4.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox5.Text.Trim() != String.Empty)
                    {
                        if(!fecha.ConvertirstringFecha( textBox5.Text ))
                        {
                            strErrores += "Fecha no válida." + Environment.NewLine;
                            textBox5.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            fecha.ConvertirstringFecha( textBox5.Text );
                            if(!fecha.VerificarFecha())
                            {
                                strErrores += "Fecha no válida." + Environment.NewLine;
                                textBox5.BackColor = System.Drawing.Color.Red;
                            }
                            else
                                Parametros[2] = textBox5.Text;
                        }

                    }
                    else
                    {
                        strErrores += "Fecha vacía." + Environment.NewLine;
                        textBox5.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], Parametros[3], "", "", "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Coach", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Coach", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;

                case "Teams":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox2.Items.IndexOf( (comboBox2.SelectedItem) ) < 0)
                        {
                            strErrores += "ID Coach no válido." + Environment.NewLine;
                            comboBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            try
                            {
                                if(comboBox2.Text.Trim() != String.Empty)
                                {
                                    conexion.consultarDataSet( ref dataS, "Teams", "select * from Teams where T_idCoach = " + comboBox2.SelectedValue.ToString() );
                                    if(dataS.Tables["Teams"].Rows[0][0] != null)
                                    {
                                        strErrores += "ID Coach existente. Elija otro." + Environment.NewLine;
                                        comboBox2.BackColor = System.Drawing.Color.Red;
                                    }
                                    else
                                    {
                                        Parametros[0] = comboBox2.SelectedValue.ToString();
                                    }
                                }
                                else
                                {
                                    strErrores += "ID Coach vacío." + Environment.NewLine;
                                    comboBox2.BackColor = System.Drawing.Color.Red;
                                }
                            }
                            catch(System.IndexOutOfRangeException)
                            {
                                Parametros[0] = comboBox2.SelectedValue.ToString();
                            }
                            catch(System.Exception err)
                            {
                                strErrores += "Error en ID Coach. " + err.Message + Environment.NewLine;
                                comboBox2.BackColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb2, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox2.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox3.Items.IndexOf( (comboBox3.SelectedItem) ) < 0)
                        {
                            strErrores += "País no válido." + Environment.NewLine;
                            comboBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            try
                            {
                                if(comboBox3.Text.Trim() != String.Empty)
                                {
                                    Parametros[1] = comboBox3.SelectedValue.ToString();
                                }
                                else
                                {
                                    strErrores += "País vacío." + Environment.NewLine;
                                    comboBox3.BackColor = System.Drawing.Color.Red;
                                }
                            }
                            catch(System.IndexOutOfRangeException)
                            {
                                Parametros[1] = comboBox3.SelectedValue.ToString();
                            }
                            catch(System.Exception err)
                            {
                                strErrores += "Error País. " + err.Message + Environment.NewLine;
                                comboBox3.BackColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb3, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox4.Text.Trim() != String.Empty)
                        {
                            if(textBox4.Text.Length > 20)
                            {
                                strErrores += "Nombre demasiado largo." + Environment.NewLine;
                                textBox4.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                conexion.consultarDataSet( ref dataS, "Teams", "select * from Teams where T_NombreTeam = '" + textBox4.Text + "'" );
                                if(dataS.Tables["Teams"].Rows[0][0] != null)
                                {
                                    strErrores += "Nombre existente. Elija otro." + Environment.NewLine;
                                    textBox4.BackColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    if(textBox4.Text.All( char.IsDigit ))
                                    {
                                        strErrores += "No se admiten números en el nombre" + Environment.NewLine;
                                        textBox4.BackColor = System.Drawing.Color.Red;
                                    }
                                    else
                                        Parametros[2] = textBox4.Text;
                                }
                            }
                        }
                        else
                        {
                            strErrores += "Nombre vacío." + Environment.NewLine;
                            textBox4.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        if(textBox4.Text.All( char.IsDigit ))
                        {
                            strErrores += "No se admiten números en el nombre" + Environment.NewLine;
                            textBox4.BackColor = System.Drawing.Color.Red;
                        }
                        else
                            Parametros[2] = textBox4.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Error en Nombre. " + err.Message + Environment.NewLine;
                        textBox4.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox5.Text.Trim() != String.Empty)
                        {
                            if(textBox5.Text.Length > 25)
                            {
                                strErrores += "Nombre completo demasiado largo." + Environment.NewLine;
                                textBox5.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                conexion.consultarDataSet( ref dataS, "Teams", "select * from Teams where T_NombreCompleto = '" + textBox5.Text + "'" );
                                if(dataS.Tables["Teams"].Rows[0][0] != null)
                                {
                                    strErrores += "Nombre completo existente. Elija otro." + Environment.NewLine;
                                    textBox5.BackColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    if(textBox5.Text.All( char.IsDigit ))
                                    {
                                        strErrores += "No se admiten números en el nombre completo" + Environment.NewLine;
                                        textBox5.BackColor = System.Drawing.Color.Red;
                                    }
                                    else
                                        Parametros[3] = textBox5.Text;
                                }
                            }
                        }
                        else
                        {
                            strErrores += "Nombre completo vacío." + Environment.NewLine;
                            textBox5.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        if(textBox5.Text.All( char.IsDigit ))
                        {
                            strErrores += "No se admiten números en el nombre completo" + Environment.NewLine;
                            textBox5.BackColor = System.Drawing.Color.Red;
                        }
                        else
                            Parametros[3] = textBox5.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Error en Nombre Completo. " + err.Message + Environment.NewLine;
                        textBox5.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], Parametros[3], "", "", "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Team", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Team", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;
                
                case "Jugadores":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox2.Items.IndexOf( comboBox2.SelectedItem ) < 0)
                        {
                            strErrores += "ID Team no válido." + Environment.NewLine;
                            comboBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[0] = comboBox2.SelectedValue.ToString();
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb2, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox2.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {

                        if(comboBox3.Items.IndexOf( comboBox3.SelectedItem ) < 0)
                        {
                            strErrores += "Rol no válido." + Environment.NewLine;
                            comboBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[1] = comboBox3.Text;
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb3, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox4.Items.IndexOf( (comboBox4.SelectedItem) ) < 0)
                        {
                            strErrores += "País no válido." + Environment.NewLine;
                            comboBox4.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            try
                            {
                                if(comboBox4.Text.Trim() != String.Empty)
                                {
                                    Parametros[5] = comboBox4.SelectedValue.ToString();
                                }
                                else
                                {
                                    strErrores += "País vacío." + Environment.NewLine;
                                    comboBox4.BackColor = System.Drawing.Color.Red;
                                }
                            }
                            catch(System.IndexOutOfRangeException)
                            {
                                Parametros[5] = comboBox4.SelectedValue.ToString();
                            }

                            catch(System.Exception err)
                            {
                                strErrores += "Error País. " + err.Message + Environment.NewLine;
                                comboBox4.BackColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb4, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox4.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox5.Text.Trim() != String.Empty)
                    {
                        if(!fecha.ConvertirstringFecha( textBox5.Text ))
                        {
                            strErrores += "Fecha no válida." + Environment.NewLine;
                            textBox5.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            fecha.ConvertirstringFecha( textBox5.Text );
                            if(!fecha.VerificarFecha())
                            {
                                strErrores += "Fecha no válida." + Environment.NewLine;
                                textBox5.BackColor = System.Drawing.Color.Red;
                            }
                            else
                                Parametros[4] = textBox5.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Fecha vacía." + Environment.NewLine;
                        textBox5.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox6.Text.Trim() != String.Empty)
                        {
                            if(textBox6.Text.Length > 25)
                            {
                                strErrores += "Nombre demasiado largo." + Environment.NewLine;
                                textBox6.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                if(textBox6.Text.All( char.IsDigit ))
                                {
                                    strErrores += "No se admiten números en el nombre" + Environment.NewLine;
                                    textBox6.BackColor = System.Drawing.Color.Red;
                                }
                                else
                                    Parametros[3] = textBox6.Text;
                            }
                        }
                        else
                        {
                            strErrores += "Nombre vacío." + Environment.NewLine;
                            textBox6.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        if(textBox6.Text.All( char.IsDigit ))
                        {
                            strErrores += "No se admiten números en el nombre" + Environment.NewLine;
                            textBox6.BackColor = System.Drawing.Color.Red;
                        }
                        else
                            Parametros[3] = textBox6.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Error en Nombre. " + err.Message + Environment.NewLine;
                        textBox6.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox7.Text.Trim() != String.Empty)
                        {
                            if(textBox7.Text.Length > 20)
                            {
                                strErrores += "Nick demasiado largo." + Environment.NewLine;
                                textBox7.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                conexion.consultarDataSet( ref dataS, "Jugadores", "select * from Jugadores where J_Nick = '" + textBox7.Text + "'" );
                                if(dataS.Tables["Jugadores"].Rows[0][0] != null)
                                {
                                    strErrores += "Nick existente. Elija otro." + Environment.NewLine;
                                    textBox7.BackColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    if(textBox7.Text.All( char.IsDigit ))
                                    {
                                        strErrores += "No se admiten números en el Nick" + Environment.NewLine;
                                        textBox7.BackColor = System.Drawing.Color.Red;
                                    }
                                    else
                                        Parametros[2] = textBox7.Text;
                                }
                            }
                        }
                        else
                        {
                            strErrores += "Nick vacío." + Environment.NewLine;
                            textBox7.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        if(textBox7.Text.All( char.IsDigit ))
                        {
                            strErrores += "No se admiten números en el Nick" + Environment.NewLine;
                            textBox7.BackColor = System.Drawing.Color.Red;
                        }
                        else
                            Parametros[2] = textBox7.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Error en Nick. " + err.Message + Environment.NewLine;
                        textBox7.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Jugador", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Jugador", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;
                
                case "Partidas":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {

                        if(comboBox2.Items.IndexOf( comboBox2.SelectedItem ) < 0)
                        {
                            strErrores += "Fase no válido." + Environment.NewLine;
                            comboBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[0] = comboBox2.Text;
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb2, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox2.BackColor = System.Drawing.Color.Red;
                    }                    
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox3.Text.Trim() != String.Empty)
                    {
                        if(!fecha.ConvertirstringFecha( textBox3.Text ))
                        {
                            strErrores += "Fecha no válida." + Environment.NewLine;
                            textBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else 
                        {
                            fecha.ConvertirstringFecha( textBox3.Text );
                            if(!fecha.VerificarFecha())
                            {
                                strErrores += "Fecha no válida." + Environment.NewLine;
                                textBox3.BackColor = System.Drawing.Color.Red;
                            }
                            else
                                Parametros[1] = textBox3.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Fecha vacía." + Environment.NewLine;
                        textBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], "", "", "", "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Partida", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Partida", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;

                case "TeamxPartidas":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox1.Items.IndexOf( comboBox1.SelectedItem ) < 0)
                        {
                            strErrores += "ID Partida no válido." + Environment.NewLine;
                            comboBox1.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[0] = comboBox1.Text;
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb1, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox1.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox2.Items.IndexOf( comboBox2.SelectedItem ) < 0)
                        {
                            strErrores += "ID Team no válido." + Environment.NewLine;
                            comboBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[1] = comboBox2.SelectedValue.ToString();
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb2, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox2.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox3.Text.Trim() != String.Empty)
                    {
                        if(!textBox3.Text.All( char.IsDigit ))
                        {
                            strErrores += "Puntos no válidos." + Environment.NewLine;
                            textBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            if(Convert.ToInt32( textBox3.Text ) <= 3)
                                Parametros[2] = textBox3.Text;
                            else
                            {
                                strErrores += "Puntos no válidos." + Environment.NewLine;
                                textBox3.BackColor = System.Drawing.Color.Red;
                            }
                        }
                    }
                    else
                    {
                        strErrores += "Puntos vacíos." + Environment.NewLine;
                        textBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], "", "", "", "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_TeamxPartida", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_TeamxPartida", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;

                case "Encuentros":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox1.Text.Trim() != String.Empty)
                    {
                        if(!textBox1.Text.All( char.IsDigit ))
                        {
                            strErrores += "ID Encuentro no válido." + Environment.NewLine;
                            textBox1.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            conexion.consultarDataSet( ref dataS, "Encuentros", "select count(*) from Encuentros where E_IdPartida = " + comboBox2.Text );
                            if(dataS.Tables["Encuentros"].Rows[0][0].ToString() == Convert.ToString(5) )
                            {
                                strErrores += "Cantidad máxima de encuentros." + Environment.NewLine;
                                textBox1.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                Parametros[0] = textBox1.Text;
                            }
                        }
                    }
                    else
                    {
                        strErrores += "ID Encuentro vacío." + Environment.NewLine;
                        textBox1.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox2.Items.IndexOf( comboBox2.SelectedItem ) < 0)
                        {
                            strErrores += "ID Partida no válido." + Environment.NewLine;
                            comboBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[1] = comboBox2.Text;
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb2, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox2.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox3.Items.IndexOf( comboBox3.SelectedItem ) < 0)
                        {
                            strErrores += "ID Ganador no válido." + Environment.NewLine;
                            comboBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[2] = comboBox3.SelectedValue.ToString();
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb3, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], "", "", "", "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Encuentro", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Encuentro", comando );

                        MessageBox.Show( "Cargar exitosa.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;

                case "JugadoresXEncuentros":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox1.Items.IndexOf( comboBox1.SelectedItem ) < 0)
                        {
                            strErrores += "ID Encuentro no válido." + Environment.NewLine;
                            comboBox1.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[0] = comboBox1.SelectedValue.ToString();
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb1, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox1.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox2.Items.IndexOf( comboBox2.SelectedItem ) < 0)
                        {
                            strErrores += "ID Jugador no válido." + Environment.NewLine;
                            comboBox2.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[1] = comboBox2.SelectedValue.ToString();
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb2, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox2.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(comboBox3.Items.IndexOf( comboBox3.SelectedItem ) < 0)
                        {
                            strErrores += "ID Partida no válido." + Environment.NewLine;
                            comboBox3.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[2] = comboBox3.SelectedValue.ToString();
                        }
                    }
                    catch(System.Exception err)
                    {
                        strErrores += "Source del cmb3, vacía." + Environment.NewLine + err.Message + Environment.NewLine;
                        comboBox3.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox4.Text.Trim() != String.Empty)
                    {
                        if(textBox4.Text.Length > 20)
                        {
                            strErrores += "Personaje demasiado largo." + Environment.NewLine;
                            textBox4.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            if(textBox4.Text.All( char.IsDigit ))
                            {
                                strErrores += "No se admiten números en el Personaje" + Environment.NewLine;
                                textBox4.BackColor = System.Drawing.Color.Red;
                            }
                            else
                                Parametros[3] = textBox4.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Personaje vacío." + Environment.NewLine;
                        textBox4.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox5.Text.Trim() != String.Empty)
                    {
                        if(!textBox5.Text.All( char.IsDigit ))
                        {
                            strErrores += "Creep Score no válida." + Environment.NewLine;
                            textBox5.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[4] = textBox5.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Creep Score vacía." + Environment.NewLine;
                        textBox5.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox6.Text.Trim() != String.Empty)
                    {
                        if(!textBox6.Text.All( char.IsDigit ))
                        {
                            strErrores += "Kills no válido." + Environment.NewLine;
                            textBox6.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                             Parametros[5] = textBox6.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Kills vacío." + Environment.NewLine;
                        textBox6.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox7.Text.Trim() != String.Empty)
                    {
                        if(!textBox7.Text.All( char.IsDigit ))
                        {
                            strErrores += "Deaths no válido." + Environment.NewLine;
                            textBox7.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Parametros[6] = textBox7.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Deaths vacío." + Environment.NewLine;
                        textBox7.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox8.Text.Trim() != String.Empty)
                    {
                        if(!textBox8.Text.All( char.IsDigit ))
                        {
                            strErrores += "Assists no válido." + Environment.NewLine;
                            textBox8.BackColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                             Parametros[7] = textBox8.Text;
                        }
                    }
                    else
                    {
                        strErrores += "Assists vacío." + Environment.NewLine;
                        textBox8.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7] );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_JugadoresXEncuentros", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_JugadoresXEncuentros", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;

                case "Usuarios":
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox2.Text.Trim() != String.Empty)
                        {
                            if(textBox2.Text.Length > 20)
                            {
                                strErrores += "Usuario demasiado largo." + Environment.NewLine;
                                textBox2.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                if(textBox2.Text.Length < 5)
                                {
                                    strErrores += "Usuario demasiado corto. Mínimo de 5 caracteres" + Environment.NewLine;
                                    textBox2.BackColor = System.Drawing.Color.Red;
                                }
                                else
                                {
                                    conexion.consultarDataSet( ref dataS, "Usuarios", "select * from Usuarios where U_Usuario = '" + textBox2.Text + "'" );
                                    if(dataS.Tables["Usuarios"].Rows[0][0] != null)
                                    {
                                        strErrores += "Usuario existente. Elija otro." + Environment.NewLine;
                                        textBox2.BackColor = System.Drawing.Color.Red;
                                    }
                                    else
                                    {
                                        //if(textBox2.Text.All( char.IsDigit ))
                                        //{
                                        //    strErrores += "No se admiten números en el nick" + Environment.NewLine;
                                        //    textBox2.BackColor = System.Drawing.Color.Red;
                                        //}
                                        //else
                                            Parametros[0] = textBox2.Text;
                                    }
                                }
                            }
                        }
                        else
                        {
                            strErrores += "Usuario vacío." + Environment.NewLine;
                            textBox2.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        //if(textBox2.Text.All( char.IsDigit ))
                        //{
                        //    strErrores += "No se admiten números en el nick" + Environment.NewLine;
                        //    textBox2.BackColor = System.Drawing.Color.Red;
                        //}
                        //else
                            Parametros[0] = textBox2.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += err.Message + Environment.NewLine;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    try
                    {
                        if(textBox3.Text.Trim() != String.Empty)
                        {
                            if(textBox3.Text.Length > 20)
                            {
                                strErrores += "Contraseña demasiado larga." + Environment.NewLine;
                                textBox3.BackColor = System.Drawing.Color.Red;
                            }
                            else
                            {
                                Parametros[1] = textBox3.Text;
                            }
                        }
                        else
                        {
                            strErrores += "Contraseña vacía." + Environment.NewLine;
                            textBox3.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    catch(System.IndexOutOfRangeException)
                    {
                        Parametros[1] = textBox3.Text;
                    }
                    catch(System.Exception err)
                    {
                        strErrores += err.Message + Environment.NewLine;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(textBox4.Text.Trim() != String.Empty)
                    {
                        if(textBox3.Text != textBox4.Text)
                        {
                            strErrores += "Las contraseñas no coinciden." + Environment.NewLine;
                            textBox3.BackColor = System.Drawing.Color.Red;
                            textBox4.BackColor = System.Drawing.Color.Red;
                        }
                    }
                    else
                    {
                        strErrores += "Repetición de contraseña vacía." + Environment.NewLine;
                        textBox4.BackColor = System.Drawing.Color.Red;
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////
                    if(strErrores.Trim() == String.Empty)
                    {
                        ArmarParametros( cmbEleccion.Text, ref comando, Parametros[0], Parametros[1], Parametros[2], Parametros[3], "", "", "", "" );
                        if(Environment.MachineName != "DESKTOP-I05G4V3")
                            EjecutarInsert( "Data Source=localhost\\sqlexpress;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Usuario", comando );
                        else
                            EjecutarInsert( "Data Source=DESKTOP-I05G4V3;Initial Catalog=Torneo;Integrated Security=True",
                                "Agregar_Usuario", comando );

                        MessageBox.Show( "Cargar exitosa.", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
                        resetAllCtrls();
                    }
                    else
                        MessageBox.Show( strErrores, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                    break;
            }
        }

        // EVENTOS
        private void ingresoFecha_KP ( ref KeyPressEventArgs e, ref TextBox txtBox )
        {
            if((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8)
            {
                if(txtBox.Text.Length >= 10 && e.KeyChar != 8)
                    e.Handled = true;
                else
                {
                    if(e.KeyChar != 8)
                    {

                        if(txtBox.Text.Length >= 2)
                        {
                            try
                            {
                                if(txtBox.Text.Length == 2)
                                    txtBox.Text += "/";
                                txtBox.SelectionStart = txtBox.Text.Length;
                            }
                            catch(System.FormatException)
                            {
                            }
                            if(txtBox.Text.Length == 5)
                            {
                                try
                                {
                                    txtBox.Text += "/";
                                    txtBox.SelectionStart = txtBox.Text.Length;
                                }
                                catch(System.FormatException)
                                {
                                }
                            }
                            if(txtBox.Text.Length == 9)
                            {
                                try
                                {
                                    txtBox.Text = txtBox.Text.Remove( txtBox.Text.IndexOf( '/' ), 1 );
                                    txtBox.Text = txtBox.Text.Remove( txtBox.Text.IndexOf( '/' ), 1 );
                                    txtBox.Text = txtBox.Text.Insert( 2, "/" );
                                    txtBox.Text = txtBox.Text.Insert( 5, "/" );
                                    txtBox.SelectionStart = txtBox.Text.Length;
                                }
                                catch(System.Exception)
                                {
                                }
                            }
                        }
                    }
                }
            }
            else
                e.Handled = true;
        }

        private void ingresoFecha_TC (ref TextBox txtBox)
        {
            txtBox.BackColor = System.Drawing.SystemColors.Window;
            if(txtBox.Text.Length == 10)
            {
                fecha.ConvertirstringFecha( txtBox.Text );
                if(!fecha.VerificarFecha())
                    txtBox.BackColor = System.Drawing.Color.Red;
            }
        }

        private void textBox3_KeyPress( object sender, KeyPressEventArgs e )
        {
            ingresoFecha_KP( ref e, ref textBox3 );
        }

        private void textBox4_KeyPress( object sender, KeyPressEventArgs e )
        {
            ingresoFecha_KP( ref e, ref textBox4 );
        }

        private void textBox5_KeyPress( object sender, KeyPressEventArgs e )
        {
            ingresoFecha_KP( ref e, ref textBox5 );
        }

        private void textBox3_TextChanged( object sender, EventArgs e )
        {
            ingresoFecha_TC( ref textBox3 );
        }

        private void textBox4_TextChanged( object sender, EventArgs e )
        {
            ingresoFecha_TC( ref textBox4 );
        }

        private void textBox5_TextChanged( object sender, EventArgs e )
        {
            ingresoFecha_TC( ref textBox5 );
        }

        private void textBox2_TextChanged( object sender, EventArgs e )
        {
            textBox2.BackColor = System.Drawing.SystemColors.Window;
        }

        private void textBox6_TextChanged( object sender, EventArgs e )
        {
            textBox6.BackColor = System.Drawing.SystemColors.Window;
        }

        private void textBox7_TextChanged( object sender, EventArgs e )
        {
            textBox7.BackColor = System.Drawing.SystemColors.Window;
        }

        private void textBox1_TextChanged( object sender, EventArgs e )
        {
            textBox1.BackColor = System.Drawing.SystemColors.Window;
        }

        private void comboBox1_TextChanged( object sender, EventArgs e )
        {
            comboBox1.BackColor = System.Drawing.SystemColors.Window;
        }

        private void comboBox2_TextChanged( object sender, EventArgs e )
        {
            comboBox2.BackColor = System.Drawing.SystemColors.Window;
        }

        private void comboBox3_TextChanged( object sender, EventArgs e )
        {
            comboBox3.BackColor = System.Drawing.SystemColors.Window;
        }

        private void comboBox4_TextChanged( object sender, EventArgs e )
        {
            comboBox4.BackColor = System.Drawing.SystemColors.Window;
        }

        private void cargarPartidasXEncuentro( object sender, EventArgs e )
        {
            if(comboBox1.Text != String.Empty)
            {
                comboBox3.DataSource = null;
                comboBox3.Items.Clear();
                if(dataS.Tables["PartidasXEnc"] != null)
                    dataS.Tables["PartidasXEnc"].Clear();
                conexion.consultarDataSet( ref dataS, "PartidasXEnc", "select * from Encuentros where E_IdEncuentro = " + comboBox1.Text.ToString() );
                try
                {  
                    comboBox3.DataSource = dataS.Tables["PartidasXEnc"];
                    comboBox3.DisplayMember = "E_IdPartida";
                    comboBox3.ValueMember = "E_IdPartida";
                }
                catch(System.Exception)
                {
                    MessageBox.Show( "No se pudo llenar la lista de Encuentros", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                }
            }
        }

        //

        private void ArmarParametros( String Tabla, ref SqlCommand comando, string a, string b, string c, string d, string e, string f, string g, string h )
        {
            SqlParameter parametros = new SqlParameter();
            switch(Tabla)
            {
                case "Coaches":
                    parametros = comando.Parameters.Add( "@nick", SqlDbType.VarChar, 10 );
                    parametros.Value = a;
                    parametros = comando.Parameters.Add( "@nombre", SqlDbType.VarChar, 25 );
                    parametros.Value = b;
                    parametros = comando.Parameters.Add( "@fechaN", SqlDbType.SmallDateTime );
                    parametros.Value = Convert.ToDateTime( c );
                    parametros = comando.Parameters.Add( "@pais", SqlDbType.Int );
                    parametros.Value = d;
                    break;
                case "Teams":
                    parametros = comando.Parameters.Add( "@idCoach", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( a );
                    parametros = comando.Parameters.Add( "@pais", SqlDbType.Int );
                    parametros.Value = b;
                    parametros = comando.Parameters.Add( "@nombreTeam", SqlDbType.VarChar, 10 );
                    parametros.Value = c;
                    parametros = comando.Parameters.Add( "@NombreCompleto", SqlDbType.VarChar, 25 );
                    parametros.Value = d;
                    break;
                case "Jugadores":
                    parametros = comando.Parameters.Add( "@idTeam", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( a );
                    parametros = comando.Parameters.Add( "@rol", SqlDbType.VarChar, 10 );
                    parametros.Value = b;
                    parametros = comando.Parameters.Add( "@nick", SqlDbType.VarChar, 10 );
                    parametros.Value = c;
                    parametros = comando.Parameters.Add( "@nombre", SqlDbType.VarChar, 25 );
                    parametros.Value = d;
                    parametros = comando.Parameters.Add( "@fechaN", SqlDbType.SmallDateTime );
                    parametros.Value = Convert.ToDateTime( e );
                    parametros = comando.Parameters.Add( "@pais", SqlDbType.Int );
                    parametros.Value = f;
                    break;
                case "Partidas":
                    parametros = comando.Parameters.Add( "@fase", SqlDbType.VarChar, 10 );
                    parametros.Value = a;
                    //parametros = comando.Parameters.Add( "@encuentrosJugados", SqlDbType.Int );
                    //parametros.Value = Convert.ToInt32( b );
                    parametros = comando.Parameters.Add( "@fecha", SqlDbType.SmallDateTime );
                    parametros.Value = Convert.ToDateTime( b );
                    break;
                case "TeamxPartidas":
                    parametros = comando.Parameters.Add( "@idPartida", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( a );
                    parametros = comando.Parameters.Add( "@idTeam", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( b );
                    //parametros = comando.Parameters.Add( "@lado", SqlDbType.VarChar, 4 );
                    //parametros.Value = c;
                    parametros = comando.Parameters.Add( "@puntos", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( c );
                    break;
                case "Encuentros":
                    parametros = comando.Parameters.Add( "@NEncuentro", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( a );
                    parametros = comando.Parameters.Add( "@idPartida", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( b );
                    //parametros = comando.Parameters.Add( "@fecha", SqlDbType.SmallDateTime );
                    //parametros.Value = Convert.ToDateTime( c );
                    parametros = comando.Parameters.Add( "@idGanador", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( c );
                    break;
                case "JugadoresXEncuentros":
                    parametros = comando.Parameters.Add( "@IdEncuentro", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( a );
                    parametros = comando.Parameters.Add( "@IdJugador", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( b );
                    parametros = comando.Parameters.Add( "@IdPartida", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( c );
                    parametros = comando.Parameters.Add( "@Personaje", SqlDbType.VarChar, 10 );
                    parametros.Value = d;
                    parametros = comando.Parameters.Add( "@CS", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( e );
                    parametros = comando.Parameters.Add( "@K", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( f );
                    parametros = comando.Parameters.Add( "@D", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( g );
                    parametros = comando.Parameters.Add( "@A", SqlDbType.Int );
                    parametros.Value = Convert.ToInt32( h );
                    break;
                case "Usuarios":
                    parametros = comando.Parameters.Add( "@User", SqlDbType.VarChar, 20 );
                    parametros.Value = a;
                    parametros = comando.Parameters.Add( "@Pass", SqlDbType.VarChar, 20 );
                    parametros.Value = b;
                    break;
            }
        }

        private void EjecutarInsert( string ruta, string nombreP, SqlCommand comando )
        {
            try
            {
                SqlConnection Conexion = new SqlConnection( ruta );
                Conexion.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = comando;
                cmd.Connection = Conexion;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = nombreP;
                cmd.ExecuteReader();
                Conexion.Close();
            }
            catch(System.Exception err)
            {
                MessageBox.Show( "Error al ejecutar el SP" + Environment.NewLine + err.Message +
                    Environment.NewLine + "El programa se cerrará.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
                Environment.Exit( 1 );
            }
        }
    
    }
}
